<?php


abstract class BaseFunrSpoxfun extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $genr_fundacion_id;


	
	protected $funm_sponsor_id;


	
	protected $funsxf_valor;


	
	protected $funsxf_anio;

	
	protected $aGenrFundacion;

	
	protected $aFunmSponsor;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getGenrFundacionId()
	{

		return $this->genr_fundacion_id;
	}

	
	public function getFunmSponsorId()
	{

		return $this->funm_sponsor_id;
	}

	
	public function getFunsxfValor()
	{

		return $this->funsxf_valor;
	}

	
	public function getFunsxfAnio($format = 'Y-m-d')
	{

		if ($this->funsxf_anio === null || $this->funsxf_anio === '') {
			return null;
		} elseif (!is_int($this->funsxf_anio)) {
						$ts = strtotime($this->funsxf_anio);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [funsxf_anio] as date/time value: " . var_export($this->funsxf_anio, true));
			}
		} else {
			$ts = $this->funsxf_anio;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setGenrFundacionId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->genr_fundacion_id !== $v) {
			$this->genr_fundacion_id = $v;
			$this->modifiedColumns[] = FunrSpoxfunPeer::GENR_FUNDACION_ID;
		}

		if ($this->aGenrFundacion !== null && $this->aGenrFundacion->getGenrFundacionId() !== $v) {
			$this->aGenrFundacion = null;
		}

	} 
	
	public function setFunmSponsorId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->funm_sponsor_id !== $v) {
			$this->funm_sponsor_id = $v;
			$this->modifiedColumns[] = FunrSpoxfunPeer::FUNM_SPONSOR_ID;
		}

		if ($this->aFunmSponsor !== null && $this->aFunmSponsor->getFunmSponsorId() !== $v) {
			$this->aFunmSponsor = null;
		}

	} 
	
	public function setFunsxfValor($v)
	{

		if ($this->funsxf_valor !== $v) {
			$this->funsxf_valor = $v;
			$this->modifiedColumns[] = FunrSpoxfunPeer::FUNSXF_VALOR;
		}

	} 
	
	public function setFunsxfAnio($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [funsxf_anio] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->funsxf_anio !== $ts) {
			$this->funsxf_anio = $ts;
			$this->modifiedColumns[] = FunrSpoxfunPeer::FUNSXF_ANIO;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->genr_fundacion_id = $rs->getInt($startcol + 0);

			$this->funm_sponsor_id = $rs->getInt($startcol + 1);

			$this->funsxf_valor = $rs->getFloat($startcol + 2);

			$this->funsxf_anio = $rs->getDate($startcol + 3, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 4; 
		} catch (Exception $e) {
			throw new PropelException("Error populating FunrSpoxfun object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FunrSpoxfunPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			FunrSpoxfunPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FunrSpoxfunPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aGenrFundacion !== null) {
				if ($this->aGenrFundacion->isModified()) {
					$affectedRows += $this->aGenrFundacion->save($con);
				}
				$this->setGenrFundacion($this->aGenrFundacion);
			}

			if ($this->aFunmSponsor !== null) {
				if ($this->aFunmSponsor->isModified()) {
					$affectedRows += $this->aFunmSponsor->save($con);
				}
				$this->setFunmSponsor($this->aFunmSponsor);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = FunrSpoxfunPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += FunrSpoxfunPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aGenrFundacion !== null) {
				if (!$this->aGenrFundacion->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aGenrFundacion->getValidationFailures());
				}
			}

			if ($this->aFunmSponsor !== null) {
				if (!$this->aFunmSponsor->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aFunmSponsor->getValidationFailures());
				}
			}


			if (($retval = FunrSpoxfunPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FunrSpoxfunPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getGenrFundacionId();
				break;
			case 1:
				return $this->getFunmSponsorId();
				break;
			case 2:
				return $this->getFunsxfValor();
				break;
			case 3:
				return $this->getFunsxfAnio();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FunrSpoxfunPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getGenrFundacionId(),
			$keys[1] => $this->getFunmSponsorId(),
			$keys[2] => $this->getFunsxfValor(),
			$keys[3] => $this->getFunsxfAnio(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FunrSpoxfunPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setGenrFundacionId($value);
				break;
			case 1:
				$this->setFunmSponsorId($value);
				break;
			case 2:
				$this->setFunsxfValor($value);
				break;
			case 3:
				$this->setFunsxfAnio($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FunrSpoxfunPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setGenrFundacionId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setFunmSponsorId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFunsxfValor($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFunsxfAnio($arr[$keys[3]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(FunrSpoxfunPeer::DATABASE_NAME);

		if ($this->isColumnModified(FunrSpoxfunPeer::GENR_FUNDACION_ID)) $criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->genr_fundacion_id);
		if ($this->isColumnModified(FunrSpoxfunPeer::FUNM_SPONSOR_ID)) $criteria->add(FunrSpoxfunPeer::FUNM_SPONSOR_ID, $this->funm_sponsor_id);
		if ($this->isColumnModified(FunrSpoxfunPeer::FUNSXF_VALOR)) $criteria->add(FunrSpoxfunPeer::FUNSXF_VALOR, $this->funsxf_valor);
		if ($this->isColumnModified(FunrSpoxfunPeer::FUNSXF_ANIO)) $criteria->add(FunrSpoxfunPeer::FUNSXF_ANIO, $this->funsxf_anio);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(FunrSpoxfunPeer::DATABASE_NAME);

		$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->genr_fundacion_id);
		$criteria->add(FunrSpoxfunPeer::FUNM_SPONSOR_ID, $this->funm_sponsor_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		$pks = array();

		$pks[0] = $this->getGenrFundacionId();

		$pks[1] = $this->getFunmSponsorId();

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

		$this->setGenrFundacionId($keys[0]);

		$this->setFunmSponsorId($keys[1]);

	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setFunsxfValor($this->funsxf_valor);

		$copyObj->setFunsxfAnio($this->funsxf_anio);


		$copyObj->setNew(true);

		$copyObj->setGenrFundacionId(NULL); 
		$copyObj->setFunmSponsorId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new FunrSpoxfunPeer();
		}
		return self::$peer;
	}

	
	public function setGenrFundacion($v)
	{


		if ($v === null) {
			$this->setGenrFundacionId(NULL);
		} else {
			$this->setGenrFundacionId($v->getGenrFundacionId());
		}


		$this->aGenrFundacion = $v;
	}


	
	public function getGenrFundacion($con = null)
	{
		if ($this->aGenrFundacion === null && ($this->genr_fundacion_id !== null)) {
						include_once 'lib/model/om/BaseGenrFundacionPeer.php';

			$this->aGenrFundacion = GenrFundacionPeer::retrieveByPK($this->genr_fundacion_id, $con);

			
		}
		return $this->aGenrFundacion;
	}

	
	public function setFunmSponsor($v)
	{


		if ($v === null) {
			$this->setFunmSponsorId(NULL);
		} else {
			$this->setFunmSponsorId($v->getFunmSponsorId());
		}


		$this->aFunmSponsor = $v;
	}


	
	public function getFunmSponsor($con = null)
	{
		if ($this->aFunmSponsor === null && ($this->funm_sponsor_id !== null)) {
						include_once 'lib/model/om/BaseFunmSponsorPeer.php';

			$this->aFunmSponsor = FunmSponsorPeer::retrieveByPK($this->funm_sponsor_id, $con);

			
		}
		return $this->aFunmSponsor;
	}

} 